package com.xiaweizi.transitiondemo.activity;

import android.os.Bundle;
import android.transition.ChangeBounds;
import android.transition.Explode;
import android.transition.Slide;
import android.view.View;
import android.view.Window;

import com.xiaweizi.transitiondemo.R;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * description：https://mp.weixin.qq.com/s/bS2UEUlHwD8i7Gd00WSRcw
 * <br>author：caowugao
 * <br>time：2021/3/22 0022 17:43
 */
public class ShareElementActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        super.onCreate(savedInstanceState);
        setUpWindow();
        setContentView(R.layout.activity_share_element);
        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
    private void setUpWindow() {

//        window.enterTransition: 进入时候的转场效果
//        window.exitTransition: 退出时候的转场效果
//        window.reenterTransition: 重新进入的转场效果
//        window.returnTransition: 回退的时候的转场效果

        Window window = getWindow();
        window .setAllowEnterTransitionOverlap(false);
        window.setAllowReturnTransitionOverlap(false);

        Explode enter = new Explode();
        enter.setDuration(500);
        window.setEnterTransition(enter);
//        window.setExitTransition(TransitionInflater.from(this).inflateTransition(R.transition.fade_transtion));

        ChangeBounds shared = new ChangeBounds();
        window.setSharedElementEnterTransition(shared);
        window.setSharedElementExitTransition(shared);
        window.setExitTransition(shared);

        window.setReenterTransition(enter);
        Slide returnT = new Slide();
        returnT.setDuration(500);
        window.setReturnTransition(returnT);
    }
}
